package com.bosssoft.hr.jobmonitor.controller;

import com.bosssoft.hr.jobmonitor.entity.User;
import com.bosssoft.hr.jobmonitor.service.IUserService;
import com.bosssoft.hr.jobmonitor.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;
/***
 * @Author lys(cherish)
 * @Description 用户信息处理
 * @Date  2019/2/26
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger logger= LoggerFactory.getLogger(UserController.class);

    //注入用户处理服务
    @Resource(name = "xmlUserServiceImpl")
    private IUserService userService;

    /***
     * @Author lys(cherish)
     * @Description 获取所有用户列表
     * @Date  2019/2/26
     * @Param []
     * @return org.springframework.web.servlet.ModelAndView
     **/
    @RequestMapping("/list")
    public  ModelAndView goIndex(){
        logger.info(LoggerUtil.fmtLog("管理员查询所有用户"));
        List<User> allUser = userService.queryAllUser();
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.getModel().put("userList",allUser);
        return modelAndView;
    }

    /***
     * @Author lys(cherish)
     * @Description 根据用户ID获取用户
     * @Date  2019/2/26
     * @Param [id] 用户ID
     * @return com.bosssoft.hr.jobmonitor.entity.User
     **/
    @RequestMapping("/user/{id}")
    public User getUserById(@PathVariable Integer id){
        logger.info(LoggerUtil.fmtLog("管理员根据id查询用户",id));
        User user = userService.getUserById(id);
        return user;
    }

}
